<template>
	<view class="container" @touchstart="touchStart" @touchend="touchEnd">
		<!-- 公告 -->
		<view class="inform">
			<!-- 显示图标 -->
			<uni-notice-bar showIcon="true" scrollable="true" text="今天，广东省实施外国人144小时过境免签政策新闻通气会在白云机场T2航站楼举行。通报自5月1日起，广东省将正式实施外国人144小时过境免签政策。白云机场口岸成为广东三个实施该政策的入境口岸之一。">
			</uni-notice-bar>
		</view>

		<!-- 选择时间 -->
		<view class="selectTime">

		</view>

		<!-- 航班列表 -->
		<scroll-view :scroll-top="scrollTop" scroll-with-animation="true" scroll-y="true" class="scroll-plane" @scrolltolower="lower" @scroll="scroll">
			<!-- 直达 -->
			<view class="planeList" v-if="FlightList.length">
				<navigator :url="`ticketOrder?id=${item.airlineId}`" class="planeList-item" v-for="(item,index) in FlightList" :key="index">
					<view class="up-con">
						<view class="left">
							<view class="time">
								<text>{{item.startTime | getTime}}</text>
								<text>——</text>
								<text>{{item.endTime | getTime}}</text>
							</view>
							<view class="place">
								<text>{{item.startAirportName | getAirport}}</text>
								<text>——</text>
								<text>{{item.endAirportName | getAirport}}</text>
							</view>
						</view>
						<view class="right">
							<view class="price">
								<span>¥</span>
								<text>{{item.commonCost}}</text>
							</view>
							<view class="seatLv">
								<text>经济舱{{item.companyDiscount | getDisCount}}</text>
							</view>
						</view>
					</view>
					<view class="down-con">
						<text>{{item.companyName | getFlightName}}</text>
						<text>{{item.name}}</text>—
						<text>{{item.aircraftName}}</text>—
						<text>{{item.isFan | getFan}}</text>
					</view>
				</navigator>
			</view>
			<!-- 换乘 -->
			<view class="planeList">
				<view class="zhuan">为您推荐中转方案</view>
				<navigator :url="`ticketOrder?id1=${item[0].airlineId}&id2=${item[1].airlineId}`" 
							class="planeList-item" v-for="(item,index) in flightRecData" :key="index">
					<view class="up-con">
						<view class="left">
							<view class="time">
								<text>{{item[0].startTime | getTime}}</text>
								<text>——</text>
								<text>{{item[1].endTime | getTime}}</text>
							</view>
							<view class="place">
								<text>{{item[0].startAirportName | getAirport}}</text>
								<text>—</text>
								<text>({{item[0].endAirportName | getAirport}})</text>
								<text>—</text>
								<text>{{item[1].endAirportName | getAirport}}</text>
							</view>
						</view>
						<view class="right">
							<view class="price">
								<span>¥</span>
								<text>{{item[0].commonCost+item[1].commonCost}}</text>
							</view>
							<view class="seatLv">
								<text>经济舱{{item[0].companyDiscount | getDisCount}}</text>
							</view>
						</view>
					</view>
					<view class="down-con">
						<!-- <text>{{item.companyName | getFlightName}}</text>
						<text>{{item.name}}</text>—
						<text>{{item.aircraftName}}</text>—
						<text>{{item.isFan | getFan}}</text> -->
					</view>
					<view class="transfer">
						<view class="transfer1">
							<text>1程</text>
							<text>{{item[0].companyName | getFlightName}}{{item[0].name}}</text>
							<text>{{item[0].aircraftName}}</text>
							<text>{{item[0].endAirportName | getAirport}}下</text>
						</view>
						<view class="transfer2">
							<text>2程</text>
							<text>{{item[1].companyName | getFlightName}}{{item[1].name}}</text>
							<text>{{item[1].aircraftName}}</text>
							<text>{{item[0].endAirportName | getAirport}}上</text>
						</view>
					</view>
				</navigator>
				
			</view>
		</scroll-view>
		
		<!-- 底部悬浮框 -->
		<view v-if="isShow" class="bottom-bar">
			<text @click="toDirect">直达</text>
			<text>|</text>
			<text @click="toTransfer">换乘</text>
		</view>
		
	</view>
</template>

<script>
	import {
		formatDate
	} from "../../../common/utils.js"

	export default {
		data() {
			return {
				FlightList: [],
				flightRecData:[],
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				isShow:true,    // 是否显示底部悬浮框
				timer:null,
			};
		},
		methods:{
			// 触摸
			touchStart(){
				// this.isShow=false
			},
			touchEnd(){
				// this.isShow=true
			},
			// 滚动到底部
			lower(e) {
				uni.showToast({
					icon: "none",
					duration: 1000,
					title: "没有更多了"
				})
			},
			// 滚动
			scroll(e) {
				this.old.scrollTop = e.detail.scrollTop
				this.isShow=false
				// 防抖
				if (this.timer) clearTimeout(this.timer)
				this.timer=setTimeout(()=>{
				    this.isShow=true
				},200)
				
			},
			// 跳到直达
			toDirect(){
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = -100
				});
			},
			// 跳到换乘
			toTransfer(){
				let that=this
				let height=0
				// setTimeout(()=>{
					
				// },500)
				uni.getSystemInfo({
					success:function(res){
						// console.log(res.windowWidth); // 屏幕的宽度
						let info = uni.createSelectorQuery().select(".planeList-item");
						info.boundingClientRect(function(data) { //data - 各种参数
							height=data.height    // 获取元素宽度
							
							that.scrollTop = that.old.scrollTop
							that.$nextTick(function() {
								that.scrollTop = (that.FlightList.length)*60+(that.FlightList.length)*height*2
							});
						}).exec()
					}
				})
				
			}
		},
		filters: {
			getTime(time) {
				let date = new Date(time)
				return formatDate(date, 'hh:mm')
			},
			getFan(fan) {
				return fan == 0 ? "有餐食" : "无餐食"
			},
			getDisCount(count) {
				return count == 1 ? "" : count + "折"
			},
			getAirport(port){
				return port.slice(0,4)
			},
			getFlightName(fly){
				return fly.slice(0,1)+fly.slice(2,3)
			}
		},
		created() {
			this.FlightList = this.$store.state.flightData
			this.flightRecData = this.$store.state.flightRecData
			console.log(this.flightRecData);
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100%;
		background-color: $uni-color-bg;
		
		// 通知
		.inform{
			padding: 10rpx;
			uni-notice-bar{
				border-radius: 20rpx;
			}
		}
		
		// 底部悬浮框
		.bottom-bar{
			display: flex;
			border-radius: 20rpx;
			justify-content: space-around;
			line-height: 80rpx;
			color: white;
			background-color: #47484d;
			position: fixed;
			left: 100rpx;
			right: 100rpx;
			bottom: 30rpx;
			opacity: .9;
			.colorY{
				color: #d5bb0f;
			}
		}
		
		.scroll-plane{
			background-color: $uni-color-bg;
			height: 100%;
			// 航班列表
			.planeList {
				// 换乘
				.zhuan{
					font-size: 32rpx;
					color: white;
					margin-left: 20rpx;
				}
				.planeList-item {
					border-radius: 10rpx;
					background-color: white;
					margin: 15rpx 25rpx;
					padding: 20rpx;
			
					// 上部分，上两行
					.up-con {
						display: flex;
						// justify-content: space-around;
			
						.left {
							margin-left: 40rpx;
							flex: 10;
							.time {
								color: black;
								font-size: 36rpx;
								margin-bottom: 15rpx;
							}
						}
			
						.right {
							flex: 3;
							.price {
								font-size: 48rpx;
								font-weight: 700;
								color: orange;
								span{
									margin-right: 5rpx;
									font-size: 24rpx;
									font-weight: 500;
								}
							}
						}
					}
					
					.down-con{
						margin-top: 15rpx;
						font-size: 26rpx;
						text:nth-of-type(4){
							color: green;
						}
					}
					
					.transfer{
						border-top: dashed 4rpx #eee;
						padding-top: 10rpx;
						.transfer1{
							display: flex;
							justify-content: space-around;
							text:nth-of-type(1){
								background-color: #fbeb64;
								border-radius: 10rpx;
								padding: 5rpx 10rpx;
							}
						}
						.transfer2{
							margin-top: 8rpx;
							display: flex;
							justify-content: space-around;
							text:nth-of-type(1){
								background-color: #fbeb64;
								border-radius: 10rpx;
								padding: 5rpx 10rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
